package cn.frank.util;

import cn.frank.mapper.oracle.BB_CESHI_DCBDHZMapper;
import cn.frank.mapper.oracle.CASE_ORDERMapper;
import cn.frank.service.WebSocketService;
import cn.frank.service.mysql.ISalesDatasService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author Frank
 * @date 05-23
 */
@Component
//@PropertySource("classpath:applicaion-oracle.yml")
public class DataStatisticsService {
    //@Value("${jdbc-url}")
    //private String url;
    //@Value("${jdbc-driver}")
    //private String driver;
    //@Value("${jdbc-username}")
    //private String username;
    //@Value("${jdbc-password}")
    //private String password;


    /*@Scheduled(fixedRate = 10000) // 每分钟执行一次
    public void performDataStatistics() {
        // 在这里编写统计数据的逻辑
        System.out.println("执行后台进程。。。。");
        // Oracle数据库的JDBC驱动类
        //String driverClass = "oracle.jdbc.driver.OracleDriver";
        //// 连接数据库的URL，格式为：jdbc:oracle:thin:@<hostname>:<port>:<dbname>
        //String connectionUrl = url;
        //// 数据库的用户名
        //String username = "NEWSYFCORE";
        //// 数据库的密码
        //String password = "NEWSYFCORE123";

        Connection connection = null;
        try{
            // 加载数据库驱动
            Class.forName(driver);
            // 建立数据库连接
            connection = DriverManager.getConnection(url, username, password);
            System.out.println("连接成功！");
            // 这里可以执行数据库操作，例如查询、更新等
        } catch (ClassNotFoundException e) {
            System.out.println("驱动类未找到！");
            e.printStackTrace();
        } catch (SQLException e) {
            System.out.println("数据库连接失败！");
            e.printStackTrace();
        } finally {
            try {
                if (connection != null && !connection.isClosed()) {
                    // 关闭连接
                    connection.close();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }*/

    @Autowired
    private CASE_ORDERMapper caseOrderMapper;
    @Autowired
    private BB_CESHI_DCBDHZMapper dcbdhzMapper;
    //@Scheduled(fixedRate = 10000) // 每分钟执行一次
    //public void performDataStatistics() {
    //    // 在这里编写统计数据的逻辑
    //    System.out.println("执行定时任务。。。。");
    //    caseOrderMapper.getCaseOrderList().forEach(x->{
    //        System.out.println(x);
    //    });
    //}

    @Autowired
    private WebSocketService webSocketService;
    @Autowired
    private ISalesDatasService salesDatasService;
    //@Scheduled(fixedRate = 20000) // 每分钟执行一次
    //public void performDataStatistics_2() {
    //    // 在这里编写统计数据的逻辑
    //    System.out.println("执行定时任务2。。。。");
    //    //dcbdhzMapper.getDcbdhzList().forEach(x->{
    //    //    System.out.println(x);
    //    //    if(x.getZzrq() != null){
    //    //        System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(x.getZzrq()));
    //    //    }
    //    //
    //    //});
    //    Object data = salesDatasService.findSalesData();
    //    webSocketService.sendMessage("/topic/sales", data);
    //}
}
